package org.chen.controller;

import lombok.extern.slf4j.Slf4j;
import org.chen.domain.dto.TranslateTextDTO;
import org.chen.domain.response.Result;
import org.chen.domain.vo.TranslatedTextVO;
import org.chen.service.TranslationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/translation")
@Slf4j
public class TranslationController {

    @Autowired
    private TranslationService translationService;
    
    /**
     * 获取支持的语言列表
     */
    @GetMapping("/languages")
    public Result<Map<String, Map<String, String>>> getSupportedLanguages() {
        return Result.success(translationService.getSupportedLanguages());
    }
    
    /**
     * 翻译单个文本
     */
    @PostMapping("/text")
    public Result<TranslatedTextVO> translateText(@RequestBody TranslateTextDTO dto) {
        String translatedText = translationService.translate(dto.getText(), dto.getTargetLanguage());
        TranslatedTextVO vo = new TranslatedTextVO();
        vo.setOriginalText(dto.getText());
        vo.setTranslatedText(translatedText);
        vo.setTargetLanguage(dto.getTargetLanguage());
        return Result.success(vo);
    }
}